package com.shigu.dailyReport.service;

import com.opentae.data.mall.beans.DailyMoneyReport;
import com.opentae.data.mall.beans.TradeReport;
import com.opentae.data.mall.beans.VipReport;
import com.opentae.data.mall.examples.DailyMoneyReportExample;
import com.opentae.data.mall.examples.TradeReportExample;
import com.opentae.data.mall.examples.VipReportExample;
import com.opentae.data.mall.interfaces.DailyMoneyReportMapper;
import com.opentae.data.mall.interfaces.SaleBonusReportMapper;
import com.opentae.data.mall.interfaces.TradeReportMapper;
import com.opentae.data.mall.interfaces.VipReportMapper;
import com.shigu.PageResponse;
import com.shigu.dailyReport.vo.DailyReportVo;
import com.shigu.dailyReport.vo.TradeReportResponse;
import com.shigu.dailyReport.vo.VipReportResponse;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/*
 * create by  过儿  2019-11-21
 * 报表
 */
@Service
public class DailyReportService {

    @Autowired
    DailyMoneyReportMapper dailyMoneyReportMapper;
    @Autowired
    TradeReportMapper tradeReportMapper;
    @Autowired
    VipReportMapper vipReportMapper;
    @Autowired
    SaleBonusReportMapper saleBonusReportMapper;

    /**
     * @description 每日数据列表
     * @author 郭尔
     * @date 2019-11-21 17:46
     */
    public PageResponse<DailyReportVo> dailyReportList(Integer page,Integer size){
        PageResponse<DailyReportVo> response = new PageResponse<>();
        DailyMoneyReportExample example = new DailyMoneyReportExample();
        example.setStartIndex((page-1)*size);
        example.setEndIndex(size);
        example.setOrderByClause("report_id desc");

        List<DailyMoneyReport> list = dailyMoneyReportMapper.selectByConditionList(example);
        int total = dailyMoneyReportMapper.countByExample(example);
        response.setTotal(total);
        response.setData(list.stream().map(o->{
            TradeReport data = tradeReportMapper.selectByPrimaryKey(o.getReportId());
            DailyReportVo vo =new DailyReportVo();
            BeanUtils.copyProperties(o,vo);
            vo.setWxPayPostfee(data.getWxPayPostfee());
            vo.setWxPayTrade(data.getWxPayTrade());
            return vo;
        }).collect(Collectors.toList()));

        return response;
    }

    /**
     *
     * @description 查询订单交易详情
     * @author 郭尔
     * @date 2019-11-23 10:36
     */
   public TradeReportResponse tradeReport(String date){
       TradeReportExample example = new TradeReportExample();
       example.createCriteria().andDateEqualTo(date);
       List<TradeReport> list = tradeReportMapper.selectByExample(example);
       TradeReport report = list.get(0);
       TradeReportResponse response = new TradeReportResponse();
       BeanUtils.copyProperties(report,response);
       return response.success();
   }

    /**
     *
     * @description vip奖励
     * @author 郭尔
     * @date 2019-11-23 15:33
     */
    public VipReportResponse vipReport(String date){
        VipReportExample example = new VipReportExample();
        example.createCriteria().andDateEqualTo(date);
        List<VipReport> list = vipReportMapper.selectByExample(example);
        VipReport report = list.get(0);
        VipReportResponse response = new VipReportResponse();
        BeanUtils.copyProperties(report,response);
        return response.success();
    }
}
